// 根据角色动态生成路由
import { defineFakeRoute } from 'vite-plugin-fake-server/client';
import { code } from './data/code';
import { tenantList } from './data/tenant';
import { login, info, routers } from './data/login';

export default defineFakeRoute([
  {
    url: '/auth/code',
    method: 'get',
    response: () => {
      return code;
    }
  },
  {
    url: '/auth/tenant/list',
    method: 'get',
    response: () => {
      return tenantList;
    }
  },
  {
    url: '/system/user/getInfo',
    method: 'get',
    response: () => {
      return info;
    }
  },
  {
    url: '/system/menu/getRouters',
    method: 'get',
    response: () => {
      return routers;
    }
  },
  {
    url: '/auth/login',
    method: 'post',
    response: ({ body }) => {
      console.log('登录参数：', body);
      if (body.username === 'admin') {
        return login;
      } else {
        return {
          success: true,
          data: {
            avatar: 'https://avatars.githubusercontent.com/u/52823142',
            username: 'common',
            nickname: '小林',
            roles: ['common'],
            permissions: ['permission:btn:add', 'permission:btn:edit'],
            accessToken: 'eyJhbGciOiJIUzUxMiJ9.common',
            refreshToken: 'eyJhbGciOiJIUzUxMiJ9.commonRefresh',
            expires: '2030/10/30 00:00:00'
          }
        };
      }
    }
  },
  {
    url: '/auth/logout',
    method: 'post',
    response: () => {
      return {
        success: true,
        data: {
          message: '注销成功'
        }
      };
    }
  }
]);
